#include<iostream>
using namespace std;
int get_day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int year)
{
	return (year%400==0)||(year%4==0&&year%100!=0);
}
int main()
{	
    int year=2024,month=6,day=2;
    int week = 7;
    while(!(week==6&&month==6&&day==1))
    {
    	int ma = get_day[month];
    	if(month==2&&check(year)) ma++;
    	day++;
    	week++;
    	if(week>7) week=1;
    	if(day>ma){
    		day=1;
    		month++;
    		if(month>12){
    			month=1;
    			year+=1;
			}
		}
	}
	cout << year << endl;
	return 0;
}
 